########################################
# RESCUER STATUS ON NUMBER OF RESCUEES #
########################################

# Author: Kasia Nalewajko
# First created: 6 February 2023
# Replicated: 17 June 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("sandwich")) install.packages("sandwich")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/RaN.Rda")

# CLEAN ---------

unique_rans <- ran %>% 
  dplyr::select(hid, rescuees_no, status, rescue_country, rescue_loc) %>% 
  unique()

# RUN MODELS ---------------------------------------------------------------

bi <- lm(formula = log(rescuees_no+1) ~ status, data = unique_rans)
countryFE <- lm(formula = log(rescuees_no+1) ~ status + rescue_country, data = unique_rans)
localityFE <- lm(formula = log(rescuees_no+1) ~ status + rescue_loc, data = unique_rans)

# COMPUTE ROBUST ERRORS ----------------------------------------------------

cov1 <- sandwich::vcovHC(bi, type = "HC1")
cov2 <- sandwich::vcovHC(countryFE, type = "HC1")
cov3 <- sandwich::vcovHC(localityFE, type = "HC1")

robust_se1 <- sqrt(diag(cov1))
robust_se2 <- sqrt(diag(cov2))
robust_se3 <- sqrt(diag(cov3))

# EXPORT -------------------------------------------------------------------

stargazer::stargazer(list(bi, countryFE, localityFE),
                     title="OLS results",
                     align=TRUE, 
                     model.numbers=TRUE,
                     dep.var.labels="Number Jewish rescuees (logged)",
                     se = list(robust_se1, robust_se2, robust_se3),
                     omit = "rescue_loc",
                     type = "latex",
                     out = "./writing/tables/OLS_RaNrescueesBYstatus.tex")

